<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <canvas id="canvas" width="500" height="500"></canvas>
  <script>
    var canvas = document.getElementById('canvas')
    var ctx = canvas.getContext('2d')

    ctx.fillStyle = '#29303b'
    ctx.fillRect(0, 0, canvas.width, canvas.height)

    function renderImage() {
      var image = new Image()
      image.onload = function () {
        ctx.drawImage(this, 400, 20, 50, 50)
      }
      image.src = 'http://react-china.org/uploads/default/37/58d7637262ac6228.png'
    }
    
    render('node.js mongodb express koa2公众号视频教程', 'MyBatis MyBatisPlus', 'SSM整合 docker dubbo', 'spring boot cloud核心技术')

    function render(){
      var arr = arguments
      
      renderText({
        text: arr[0], 
        fontSize: '45px',
        fillStyle: '#f4c150' 
      })

      for (var i=1; i<arr.length; i++) {
        renderText({
          text: arr[i], 
          fontSize: '40px',
          iNow: i
        })
      }
    }

    function renderText(opt){
      var text = opt.text || ''
      var fontSize = opt.fontSize || '40px'
      var fillStyle = opt.fillStyle || '#fff'
      var iNow = opt.iNow || 0

      ctx.beginPath()
      ctx.fillStyle = fillStyle
      ctx.font = 'normal normal 500 '+ fontSize +' Open Sans,Helvetica Neue,Helvetica,Arial,sans-serif'
      ctx.fillText(text, (canvas.width - ctx.measureText(text).width)/2, 120 + 80 * iNow)
      ctx.closePath()
    }
  </script>
</body>
</html>